package com.cll.controller.admin;


import com.cll.constant.StatusConstant;
import com.cll.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Api(tags = "店铺相关接口")
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {
    @Autowired
    private static final String KEY = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺状态
     * @param status
     * @return
     */
    @ApiOperation("商家设置店铺状态")
    @PutMapping("/{status}")
    public Result setStatus (@PathVariable Integer status){

        log.info("设置店铺状态: " +(StatusConstant.ENABLE.equals(status)?"营业中":"已打烊"));
        //设置缓存数据
        redisTemplate.opsForValue().set(KEY,status);
        //返回
        return Result.success();
    }

    /**
     * 获取店铺状态
     * @return
     */
    @ApiOperation("商家获取店铺状态")
    @GetMapping("/status")
    public Result getStatus (){
        //设置缓存数据
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("设置店铺状态: " +(StatusConstant.ENABLE.equals(status)?"营业中":"已打烊"));
        //返回
        return Result.success(status);
    }
}
